jQuery.ajaxSetup({
    'beforeSend': function(jqXHR, settings) {
       startLoadingImage();
    },
    'error': function(jqXHR, textStatus, errorThrown) {
        stopLoadingImage();
    },
    'success': function(jqXHR, textStatus) {
        stopLoadingImage();
    },
    'complete': function(jqXHR, textStatus) {
        stopLoadingImage();
    },
    'statusCode': {
    	302: function() {
    		jQuery.active=0;
    		stopLoadingImage();
        }
    }
    
});

function startLoadingImage() {
    var $preload =  $('body > .preload');
    if( !$preload.length ) {
        $preload = $('<div class="preload"></div>');
        $preload.appendTo('body');
    }
    $preload.show();
    return;
}

function stopLoadingImage() {
    if( jQuery.active < 2 )
        $('body > .preload').hide();
    
    return;
}
function forceStopLoadingImage() {
    $('body > .preload').hide();
    return;
}
function disableLoading() {
    jQuery.ajaxSetup({
        'beforeSend': function(jqXHR, settings) {
            stopLoadingImage();
        }
        
    });
}

/* Get browser information */
function getBrowserInformation() {
    /*
      FF: "Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0"
      Chrom: "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"
      Safari: "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2"
      IE: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; ShopperReports 3.1.69.0; SRS_IT_E8790676B476595135A197; .NET4.0C; .NET4.0E; AskTbPTV2/5.9.1.14019)" 

    */
    var browser = navigator.userAgent.toLowerCase();
    var objbrowser = new Object();
    objbrowser.name     = "unknow";
    objbrowser.version  = 0;
    if (browser.indexOf("firefox") > -1) {
        objbrowser.name     = "firefox";
        objbrowser.version  = 0;
        var arrMatch = browser.match(/Firefox\/(\d+\.?\d+?)/i);
        if(arrMatch.length == 2) {
            objbrowser.version = arrMatch[1];
        }
    } else if(browser.indexOf("chrome") > -1) {
        objbrowser.name     = "chrome";
        objbrowser.version  = 0;
        var arrMatch = browser.match(/Chrome\/(\d+\.?\d+?)/i);
        if(arrMatch.length == 2) {
            objbrowser.version = arrMatch[1];
        }
    } else if(browser.indexOf("safari") > -1) {
        objbrowser.name     = "safari";
        objbrowser.version  = 0;
        var arrMatch = browser.match(/Version\/(\d+\.?\d+?)/i);
        if(arrMatch.length == 2) {
            objbrowser.version = arrMatch[1];
        }
    } else if(browser.indexOf("msie") > -1) {
        objbrowser.name     = "ie";
        objbrowser.version  = 0;
        var arrMatch = browser.match(/MSIE\s+(\d+\.?\d+?)/i);
        if(arrMatch.length == 2) {
            objbrowser.version = arrMatch[1];
        }
    }
    return objbrowser;
}

